import { defHttp } from '/@/utils/http/axios';
import {
  OpmsNoticeListGetResultModel,
  OpmsNoticeModel,
  OpmsNoticePageListGetResultModel,
  OpmsNoticeParams,
  OpmsNoticePageSearchParams,
  OpmsNoticeListSearchParams,
  UpdateOpmsNoticeParams,
  OpmsNoticeIDType,
} from '/@/api/opms/model/OpmsNoticeModel';

import { UploadFileParams } from '/#/axios';
import { useGlobSetting } from '/@/hooks/setting';
import { UploadApiResult } from '../sys/model/uploadModel';

// 系统公告表接口
export enum Api {
  PublicApi = '/opms/opms-notice',
  ListApi = `/opms/opms-notice/list`,
  PageApi = `/opms/opms-notice/page`,
  BatchApi = `/opms/opms-notice/batch`,
  ExportApi = `/opms/opms-notice/export`,
  ImportApi = `/opms/opms-notice/import`,
}
/**
 * @description:  获取列表
 * @param params
 * @returns
 */
export const getOpmsNoticeList = (params?: OpmsNoticeListSearchParams) =>
  defHttp.get<OpmsNoticeListGetResultModel>({ url: Api.ListApi, params });

/**
 * @description:  分页获取列表
 * @param params
 * @returns
 */
export const getOpmsNoticePage = (params: OpmsNoticePageSearchParams) =>
  defHttp.get<OpmsNoticePageListGetResultModel>({ url: Api.PageApi, params });

/**
 * @description:  根据id获取
 * @param id
 * @returns
 */
export const getOpmsNotice = (id: OpmsNoticeIDType) =>
  defHttp.get<OpmsNoticeModel>({ url: `${Api.PublicApi}/${id}` });

/**
 * @description:  创建
 * @param params
 * @returns
 */
export const createOpmsNotice = (params: OpmsNoticeParams) =>
  defHttp.post<boolean>({ url: Api.PublicApi, params });

/**
 * @description:  更新
 * @param params
 * @returns
 */
export const updateOpmsNotice = (params: UpdateOpmsNoticeParams) =>
  defHttp.put<boolean>({ url: Api.PublicApi, params });

/**
 * @description:  物理删除
 * @param id
 * @returns
 */
export const deleteOpmsNotice = (id: OpmsNoticeIDType) =>
  defHttp.delete<boolean>({ url: `${Api.PublicApi}/${id}` });

/**
 * @description:  物理批量删除
 * @param ids
 * @returns
 */
export const deleteOpmsNoticeBatch = (ids: OpmsNoticeIDType[]) =>
  defHttp.post<boolean>({ url: Api.BatchApi, params: { ids } });

/**
 * @description:  逻辑删除
 * @param ids
 * @returns
 */
export const logicDeleteOpmsNotice = (id: OpmsNoticeIDType) =>
  defHttp.delete<boolean>({ url: `${Api.PublicApi}/${id}` });

/**
 * @description:  逻辑批量删除
 * @param ids
 * @returns
 */
export const logicDeleteOpmsNoticeBatch = (ids: OpmsNoticeIDType[]) =>
  defHttp.post<boolean>({ url: Api.BatchApi, params: { ids } });

/**
 * @description:  导出文件
 * @param ids
 * @returns
 */
export const exportOpmsNoticeListFile = (ids: OpmsNoticeIDType[]) =>
  defHttp.post<boolean>({ url: Api.ExportApi, params: { ids } });

/**
 * @description:  导入文件
 * @param ids
 * @returns
 */
export const importOpmsNoticeListFile = (
  params: UploadFileParams,
  onUploadProgress?: (progressEvent: ProgressEvent) => void,
) =>
  defHttp.uploadFile<UploadApiResult>(
    {
      url: useGlobSetting().apiUrl + Api.ImportApi,
      onUploadProgress,
    },
    params,
  );
